console.log('加载page_fate.js');
myApp.onPageInit("fate", function (page) {
	//获取url参数
	var uuid = page.query.uuid;
	var major = page.query.major;
	var minor = page.query.minor;
	//回到qblist.html时加上参数
	var url = $$('.fate-back').attr('href');
	url +="?uuid="+uuid+"&major="+major+"&minor="+minor;
	$$('.fate-back').attr('href',url);
	
	//点击开始测算
	$$('#fate .start').click(function(){
		var status = $$(this).data('status');
		//console.log(status);
		var lefttimes = $$(this).data('lefttimes');
		//console.log(lefttimes);
		if(lefttimes == '0'){
			myApp.alert("六次为一卜，请将结果截图发至玩家群，哇吖会在之后的调查报告中，告知各位的卦象解释");
			return;
		}
		//停滞状态下开启旋转
		if(status == 'stop'){
			//开始运行
			$$(this).data('status','run');
			startRotate('1',5);
		  	setTimeout("startRotate('2','5')",500);
		  	setTimeout("startRotate('3','5')",1000);
		  	setTimeout("stopRotate('1')",3000);
		  	setTimeout("stopRotate('2')",4000);
		  	setTimeout("stopRotate('3')",5000);
		  	//结束运行
		  	setTimeout(function(){
		  		$$('#fate .start').data('status','stop');
		  	},5000);
		  	//计算剩余次数
		  	setTimeout(function(){
		  		lefttimes = parseInt(lefttimes)-1;
				$$('#fate .start').data('lefttimes',lefttimes);
				//生成结果
				var times = 6-lefttimes;
				var img1res =  $$('.fate-res').data('img1res');
				var img2res =  $$('.fate-res').data('img2res');
				var img3res =  $$('.fate-res').data('img3res');
				
				var res_html = '<div class="fate-res-line"><div class="fate-res-text">第'+times+'次結果</div><div class="fate-res-img">'
					  	+'<img class="res-img" src="/treasure_hunter/2/img/guijia-'+img1res+'.png">'
					  	+'<img class="res-img" src="/treasure_hunter/2/img/guijia-'+img2res+'.png">'
					  	+'<img class="res-img" src="/treasure_hunter/2/img/guijia-'+img3res+'.png"></div></div>';
				  	
				$$('#fate .fate-res').append(res_html);
				
				$$('#fate .start').html('算<br>('+lefttimes+')');
				
				if(lefttimes == '0'){
					myApp.alert("六次为一卜，请将结果截图发至玩家群，哇吖会在之后的调查报告中，告知各位的卦象解释");
				}
		  	},5000);
		}
	  	  
    });
})